package com.market.manage.service.impl;

import com.market.manage.mapper.ArticleMapper;
import com.market.manage.po.Article;
import com.market.manage.service.ArticleService;
import com.market.po.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {
    /*service impl提供了具体的业务逻辑层代码的实现。一般接受controller传来的参数，然后进行处理。关键代码区*/
    @Resource
    private ArticleMapper articleMapper;

    /**
     * 获取待办事项
     *
     * @param pageIndex
     * @return
     */
    @Override
    public Result getAllArticle(Long userId, Long pageIndex) {
        pageIndex = Math.max(pageIndex - 1, 0) * 6;
        List<Article> articles = articleMapper.selArticle(userId, pageIndex);
        Result result = new Result();
        result.setMessage(articles);
        Long count = articleMapper.count();
        result.setTotal(count);
        return result;
    }

    @Override
    public void updStatus(Long id, String status) {
        articleMapper.updStatus(id, status);
    }

    /**
     * 根据id查找
     *
     * @param id
     * @return
     */
    @Override
    public Article getById(Long id) {
        return articleMapper.getById(id);
    }

    @Override
    public Long count() {
        return articleMapper.count();
    }

    @Override
    public void delete(Long id) {
        articleMapper.delete(id);
    }
}
